import 'package:flutter/material.dart';

class Constraintsdemo {
  /**
   * 实现一个最小高度为50，宽度尽可能大的红色容器
   */
  static Widget getWidget() {
    Widget redBox = DecoratedBox(decoration: BoxDecoration(color: Colors.red));
    return ConstrainedBox(
      constraints: BoxConstraints(
          minWidth: double.infinity, //宽度尽可能大
          minHeight: 50.0 //最小高度
          ),
      child: Container(
        height: 5.0,
        child: redBox,
      ),
    );
  }

  static Widget getWidget2(){
    return SizedBox(
        width: 100,
        height: 100,
        child: CircularProgressIndicator(
          backgroundColor: Colors.red,
          value: 0.4,
          valueColor: AlwaysStoppedAnimation(Colors.blue),
        )
    );
  }

  static Widget getWidget3(){
    Widget redBox = DecoratedBox(decoration: BoxDecoration(color: Colors.red));
    return SizedBox(
        width: 100,
        height: 100,
        child: redBox
    );
  }

  /**
   * getWidget3==getWidget4==getWidget5
   * SizedBox只是ConstrainedBox的一个定制，上面代码等价于
   */
  static Widget getWidget4(){
    Widget redBox = DecoratedBox(decoration: BoxDecoration(color: Colors.red));
    return ConstrainedBox(
      constraints: BoxConstraints.tightFor(width: 80.0,height: 80.0),
      child: redBox,
    );
  }

  /**
   * getWidget3==getWidget4==getWidget5
   * BoxConstraints.tightFor(width: 80.0,height: 80.0)等价于
   */
  static Widget getWidget5(){
    Widget redBox = DecoratedBox(decoration: BoxDecoration(color: Colors.red));
    return ConstrainedBox(
      constraints: BoxConstraints(minHeight: 80.0,maxHeight: 80.0,minWidth: 80.0,maxWidth: 80.0),
      child: redBox,
    );
  }
}
